<?php

namespace app\controller;

use app\BaseController;
use app\model\DebitClient;
use app\model\Users;
use app\services\AuthService;
use app\services\UserService;
use app\validate\DebitClientValidate;
use app\validate\UserValidate;

use think\App;

class DebitClientController extends BaseController
{


    /**
     * @var DebitClient
     */
    private $dao;

    public function __construct(App $app)
    {
        $this->dao = new DebitClient();
       
        parent::__construct($app);
    }

   
    public function add(){
        $param = $this->request->param(['name', 'card_number', 'phone', 'address', 'total_amount', 'available_credit']);

        validate(DebitClientValidate::class)
            ->scene('add')
            ->check($param);


       return $this->returnJson($this->dao->create($param));
    }

    public function getList(){
        $keyword = $this->request->param('keyword', '');

        return $this->returnJson($this->dao->where('name|address', 'like' ,'%'.$keyword.'%')->select());

    }


    public function del(DebitClient $debitClient){
        return $this->returnJson($this->dao->destroy($debitClient->id));
    }

    public function getById(DebitClient $debitClient){
        return $this->returnJson($debitClient);
    }


}